-- @owner: opentestcase023
-- @date: 2022/02/24
-- @testpoint: 在视图上创建delete on after触发器带有when条件，合理报错

--step1:建表;expect:成功
drop table if exists t_trigger_src_0048 cascade;
drop table if exists t_trigger_des_0048 cascade;
drop sequence if exists trigger_des_seq1 cascade;
create table t_trigger_src_0048(id1 int, id2 int, id3 int) with (storage_type=ustore);
create table t_trigger_des_0048(id1 int, id2 int, id3 int) with (storage_type=ustore);

--step2:在视图上创建delete on after触发器带有when条件;expect:合理报错
create or replace view t_trigger_src_0048_view1 as select * from t_trigger_src_0048;
create sequence trigger_des_seq1;
create or replace function tri_truncate_func() returns trigger as
$$
declare
begin
insert into t_trigger_des_0048 values(nextval('trigger_des_seq1'),nextval('trigger_des_seq1'),nextval('trigger_des_seq1'));
return new;
end
$$ language plpgsql;
/
drop trigger if exists truncate_trigger on t_trigger_src_0048_view1;
create trigger truncate_trigger after delete on t_trigger_src_0048_view1
for each row
when(old.id1<3)
execute procedure tri_truncate_func();
/

--step3:清理环境;expect:成功
drop table if exists t_trigger_src_0048 cascade;
drop table if exists t_trigger_des_0048 cascade;